package com.xtx.service.impl;

import com.xtx.constant.MessageConstant;
import com.xtx.dto.UserLoginDto;
import com.xtx.entity.User;
import com.xtx.exception.UserNotLoginException;
import com.xtx.mapper.UserMapper;
import com.xtx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.security.auth.login.AccountNotFoundException;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User userLogin(UserLoginDto userLoginDto) {
        String userName = userLoginDto.getUserName();
        String password = userLoginDto.getPassword();
        User user = userMapper.getByUserName(userName);
        if(user == null){
            throw new UserNotLoginException(MessageConstant.USER_NOT_EXIST);
        }
        if(!password.equals(user.getPassword())){
            throw new UserNotLoginException(MessageConstant.PASSWORD_ERROR);
        }

        return user;
    }
}
